package com.fire.control.system.module.warning.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.fire.control.system.dto.UnsolvedListDTO;
import com.fire.control.system.dto.app.AppWarningInfoVo;
import com.fire.control.system.dto.app.AppWarningLinkmanVo;
import com.fire.control.system.entity.WarningInfo;
import com.fire.control.system.statics.Type_SureWarning;
import com.fire.control.system.support.protocol.device.DeviceRequestProtocol;

public interface WarningInfoMapper {

	public int insertWarningInfo(WarningInfo warningInfo);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getUnsolvedList   
	 * @Description: 根据企业id获取所有未处理的报警  
	 */
	public List<UnsolvedListDTO> getUnsolvedList(@Param("companyId") String companyId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: searchUnsolvedWarnings   
	 * @Description: 根据条件搜索未解决的报警设备  
	 */
	public List<UnsolvedListDTO> searchUnsolvedWarnings(DeviceRequestProtocol params);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getUnsolvedList   
	 * @Description: 根据企业id获取所有已完成处理的报警  
	 */
	public List<UnsolvedListDTO> getSolvedList(@Param("companyId") String companyId);
	
	/**
	 * @author: xiechengguang 
	 * @Title: searchUnsolvedWarnings   
	 * @Description: 根据条件搜索已完成处理的报警设备  
	 */
	public List<UnsolvedListDTO> searchSolvedWarnings(DeviceRequestProtocol params);
	
	/**
	 * @author: xiechengguang 
	 * @Title: updateWarningInfoStatus   
	 * @Description: 删除已完成处理报警设备（软删除）  
	 */
	@Update("update t_warning_info w set w.status = false where w.id = #{id}")
	public int updateWarningInfoStatus(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: exportWarningByIds   
	 * @Description: 根据ids获取导出excel数据  
	 */
	public List<UnsolvedListDTO> exportWarningByIds(@Param("ids") String[] ids);
	
	/**
	 * @author: xiechengguang 
	 * @Title: applyforMaintence   
	 * @Description: 使用单位申请维保  
	 */
	public int applyforMaintence(@Param("companyId") String companyId, @Param("ids") String[] ids);
	
	/**
	 * @author: xiechengguang 
	 * @Title: getLinkman   
	 * @Description: 获取联系人  
	 */
	public List<AppWarningLinkmanVo> getLinkman(@Param("warningId") String warningId);
	
	@Select("SELECT w.* FROM t_warning_info w WHERE w.id = #{id}")
	public WarningInfo findOne(String id);
	
	/**
	 * @author: xiechengguang 
	 * @Title: updateApplyfor   
	 * @Description: app端维保申请 
	 * 更新当前状态为申请维保 
	 * 并将处理详细的处理类型标为：dispose 
	 */
	public int updateApplyfor(@Param("id") String id, @Param("sureWarning") Type_SureWarning sureWarning);
	
	/**
	 * @author: xiechengguang 
	 * @Title: updateWarningType   
	 * @Description: 更新当前状态为处理中以及报警类型    
	 */
	@Update("update t_warning_info w set w.current_status = 'processing', w.warning_type = #{warningType} where w.id = #{id}")
	public int updateWarningType(@Param("id") String id, @Param("warningType") String warningType);
	
	/**
	 * xiechengguang
	 * 完成报警
	 */
	@Update("update t_warning_info w, t_device d set d.online_status = 'normal', w.current_status = 'complete' where d.id = w.target_device_id AND w.id = #{id}")
	public int finishWarning(@Param("id") String id);
	
}
